#include <vector>
#include <map>
#include "base/abc/abc.h"
#include "base/abc/abc.h"
#include "base/main/main.h"
#include "map/mio/mio.h"
using namespace std;

class MyCompare
{
public:
    bool operator()(int v1, int v2)
    {
        return v1 > v2;
    }
};
class DelyNode
{
public:
    vector<int> topid;                         //存储输出端节点id
    vector<int> allpathcone;                   //存储所有关键路径节点
    vector<int> ndpathcone;                    //存储不重复的关键路径节点
    vector<int> tempnode;                      //临时存储一条关键路径节点id
    map<int, vector<int> > criticalpath;       //存储所有关键路径集合
    multimap<double, int, MyCompare> weight;   //记录每一个关键路径节点对应的权重值，其值是由它在关键路径搜索函数中所遍历的次数以及其所在层级位置决定的
    vector<int> weightcone;                    //保存按照权重排好序的节点id
    multimap<int, int, MyCompare> weightsort;  //将weight排好序的节点，读取其节点对应所处的层级保存
    multimap<int, int, MyCompare> levelsort;   //统计每一个层级所含节点数量，计算权重值并排序获得对应的level顺序
    vector<int> wlevel;                        //获取levelsort中排好序的level
    vector<int> replacenode;                   //用于近似替换的节点
    int count;
};

void getCriticalPath(Abc_Obj_t *pNode, DelyNode &delaynode);
void test(Abc_Ntk_t *pNtk, DelyNode &delaynode);
void SaveMessage(Abc_Ntk_t *pNtk, DelyNode &delaynode);
Abc_Ntk_t *GetBestDelayNtk(Abc_Ntk_t *pNtk, DelyNode &delaynode, double bound);
void DelayConstreplace(Abc_Ntk_t *pNtk, Abc_Obj_t *pNode,DelyNode &delaynode);
void SaveNoDuplicationId(Abc_Obj_t *pNode, DelyNode &delaynode);
void setiTemp(Abc_Ntk_t *pNtk);
void CalWeight(Abc_Ntk_t *pNtk, DelyNode &delaynode);
void sortbylevel(Abc_Ntk_t *pNtk, DelyNode &delaynode);
Abc_Ntk_t *GetBestDelayNtk1(Abc_Ntk_t *pNtk, Abc_Ntk_t *pNtk_org, double lastError, double bound, unsigned seed, DelyNode &delaynode);
float getdelay(Abc_Ntk_t *pNtk);
void cleardelaynode(Abc_Ntk_t *pNtk, DelyNode &delaynode);
float caldelay(Abc_Ntk_t *pNtk);
void calPathDistance(Abc_Ntk_t *pNtk, Abc_Obj_t *pNode, DelyNode &delaynode);
void edgereplace(Abc_Ntk_t *pNtk, Abc_Obj_t *pNode,Abc_Obj_t *pRootfanout, DelyNode &delaynode);
void SaveEachCriticalPath(Abc_Ntk_t *pNtk, DelyNode &delaynode);